function zmDialog(){
    this.openSure = function(diyJson){
        $("body").append("<div class='zm-dialog-bg'></div>");
        var dialogJson ={
            showType :"300",
            ok : function(){},
            close : function(){},
            tip:"请填写提示文字!"
        }
        dialogJson = $.extend(dialogJson,diyJson);
        var str = new StringBuilder();
        str.append("<div id='dialog_box' class='zm-dialog-box' data-animate='005' >");
        str.append("<div class='zm-dialog' >");
        str.append("<div class='zm-dialog-header '>");
        str.append("<span class='zm-dialog-title color-red'><span class='zm-dialog-title-tips-img'><img src='../images/tips-tsy.png'></span>提示语</span>");
        str.append("<span id='dialog_box_cancle' class='zm-dialog-close'>×</span>");
        str.append("</div>");
        str.append("<div class='zm-dialog-content'>");
        str.append("<div class='tips-con'>");
        str.append("<p>"+dialogJson.tip+"</p>");
        str.append("<div class='col-w-10 margin-btm10 margin-top10'>");
        str.append("<button type='button' id='dialog_box_button' class='btn btn-kept fr' >确定</button>");
        str.append("</div>");
        str.append("</div>");
        str.append("</div>");
        str.append("</div>");
        str.append("</div>");
        $("body").append(str.toString());
        var _this = $("#dialog_box");
        //var animate= "slide";
        var width = _this.width();
        var height = _this.height();
        _this.css({"marginLeft": -width / 2, "marginTop": -height / 2});
        //_this.show();
        _this.slideDown(dialogJson.showType);
        $("#dialog_box_button").click(function(){
            dialogJson.ok();
            _this.remove();
            $(".zm-dialog-bg").fadeOut().remove();
        });
        $("#dialog_box_cancle").click(function(){
            dialogJson.close();
            _this.remove();
            $(".zm-dialog-bg").fadeOut().remove();
        });
    },
        this.openConfirm=function(diyJson){
            $("body").append("<div class='zm-dialog-bg'></div>");
            var dialogJson ={
                showType :"250",
                ok : function(){},
                cancle : function(){},
                close: function(){},
                tip:"请填写提示文字!",
                okText :"确定",
                closeText : "取消"
            }
            dialogJson = $.extend(dialogJson,diyJson);
            var str = new StringBuilder();
            str.append("<div id='dialog_tip' class='zm-dialog-box' data-animate='005' style='height:150px;'>");
            str.append("<div class='zm-dialog bg-4ab1a7'>");
            str.append("<div class='zm-dialog-header '>");
            str.append("<span class='zm-dialog-title'><!--<span class='zm-dialog-title-tips-img'><img src='../images/tips-tsy.png'></span>-->提示语</span>");
            str.append("<span id='dialog_box_cancle' class='zm-dialog-close'>×</span>");
            str.append("</div>");
            str.append("<div class='zm-dialog-content'>");
            str.append("<div class='tips-con' >");
            str.append("<p>"+dialogJson.tip+"</p>");
            str.append("<div class='col-w-10 margin-top20 margin-btm10'>");
            str.append("<div class='text-center'>");
            str.append("<button class='btn btn-popup-know' id='dialog_sure' style='margin-right:15px;margin-left:65px;'>"+dialogJson.okText+"</button>");
            str.append("<button class='btn btn-popup-know  btn-close-dialog' id='dialog_cancle_button'>"+dialogJson.closeText+"</button>");
            str.append("</div>");
            str.append("</div>");
            str.append("</div>");
            str.append("</div>");
            str.append("</div>");
            str.append("</div>");
            $("body").append(str.toString());
            var _this = $("#dialog_tip");
            //var animate= "slide";
            var width = _this.width();
            var height = _this.height();
            _this.css({"marginLeft": -width / 2, "marginTop": -height / 2});
            //_this.show();
            _this.slideDown(dialogJson.showType);
            $("#dialog_sure").click(function(){
                dialogJson.ok();
                _this.remove();
                $(".zm-dialog-bg").fadeOut().remove();
            });
            $("#dialog_cancle_button").click(function(){
                dialogJson.cancle();
                _this.remove();
                $(".zm-dialog-bg").fadeOut().remove();
            });
            $("#dialog_box_cancle").click(function(){
                dialogJson.close();
                _this.remove();
                $(".zm-dialog-bg").fadeOut().remove();
            });
        }
}

var width,height;
$.fn.zmDialog=function(){
    $("body").append("<div class='zm-dialog-bg'></div>")
    var _this = $(this);
    var animate=_this.attr("data-animate");
    width = _this.width()
    height = _this.height()
    _this.css({"marginLeft": -width / 2, "marginTop": -height / 2});
    switch (animate.substr(0, 17)) {
        case "fade":
            _this.fadeIn(300);
            break;
        case "slide":
            _this.slideDown(300);
            break;
        case "zm-dialog-animate":
            _this.addClass(animate);
            _this.show()
            break;
        default:
            _this.show();
            break;
    }
}
$.fn.zmDialogClose=function(){
    $(this).hide();
    $(".zm-dialog-bg").fadeOut().remove();
}
$(document).on("click",".zm-dialog-close,.btn-close-dialog,.sure-close-dialog,.btn-kept-sure",function(){
    var _this =$(this);
    var thisDialog = _this.closest(".zm-dialog-box");
    thisDialog.attr("style","")
    var animate=thisDialog.attr("data-animate");
    switch (animate.substr(0, 17)) {
        case "fade":
            thisDialog.fadeOut(300);
            break;
        case "slide":
            thisDialog.slideUp(300);
            break;
        default:
            thisDialog.removeClass(animate);
            thisDialog.hide();
            break;
    }
    $(".zm-dialog-bg").fadeOut().remove();

})
$(document).on("click","#cancleButton,.btn-cancel,.btn-close-dialog,.sure-close-dialog,.btn-kept-sure",function(){
    var _this =$(this);
    var thisDialog = _this.closest(".zm-dialog-box");
    thisDialog.attr("style","")
    var animate=thisDialog.attr("data-animate");
    switch (animate.substr(0, 17)) {
        case "fade":
            thisDialog.fadeOut(300);
            break;
        case "slide":
            thisDialog.slideUp(300);
            break;
        default:
            thisDialog.removeClass(animate);
            thisDialog.hide();
            break;
    }
    $(".zm-dialog-bg").fadeOut().remove();

})

$(document).on("mousedown",".zm-dialog-header",function(e){
    e = window.event || e;
    e.preventDefault();
    var isMove = true;
    var _this = $(this);
    var thisDialog = _this.closest(".zm-dialog-box");
    var rectLeft = this.getBoundingClientRect().left;
    var rectTop = this.getBoundingClientRect().top;
    var startX = e.clientX;
    var startY = e.clientY;
    /*    var scorllHeight=$(document).scrollTop();
     console.log(scorllHeight);
     var scorllLeft=$(document).scrollLeft();
     console.log(scorllLeft);*/
    $(document).mousemove(function (e) {
        if(isMove){
            thisDialog.css({
                "left": (e.clientX - startX + rectLeft + width/2)+"px",
                "top": (e.clientY - startY + rectTop + height/2)+"px"
            });
        }
    }).mouseup(function () {
        isMove=false;
    });
})

dialog = new zmDialog();

(function ($) {
    var addPopup=function (ele,opt) {
        this.$element=ele;
        this.options=$.extend({},{
            tit:'',width:280,minHeight:150,maxHeight:760,showHeader:1,iframeSrc:'',btns:'',Height:'150',content:'',
            contentTextAlign:'center',iframeWidth:1500, iframeHeight:700,callBackKnow:function(){},callBackKept:function(){},callBackCancel:function(){}
        },opt);
    };
    addPopup.prototype={
        textHtml:function () {
            var texthtml='<div class="zm-popup-blocks"><div class="zm-popup-bg"></div>'+
                '<div class="zm-popup-box">'+
                '<div class="zm-popup" >'+
                '<div class="zm-popup-header">'+
                '<span class="zm-popup-title" title="'+this.options.tit+'">'+this.options.tit+'</span>'+
                '<span class="zm-popup-close">×</span>'+
                '</div>'+
                '</div>'+
                '<div class="zm-popup" >'+
                '<div class="zm-popup-content">'+this.options.content+'' +
                '<div class="iframe-box">'+this.options.iframeSrc+'</div>'+
                this.options.btns+
                '</div>'+
                '</div>'+
                '</div>'+
                '</div>';
            return texthtml;
        },
        addHmtl:function () {
            $("body").append(this.textHtml());
        },
        init:function () {
            var _this = this;
            this.addHmtl();
            this.popupBox=$("body").find(".zm-popup-box");

            this.popupBox.addClass(this.options.skin);
            this.popupBox.find(".zm-popup-title").css({width:this.options.width-50+'px'});
            this.popupBox.css({
                width:this.options.width+'px',
                height:this.options.Height+'px'
            });
            this.popupBox.find(".zm-popup-close").click(function () {
                var $this = $(this);
                if(sessionStorage.getItem("PRODUCT-CATEGORY-EDIT-STATE") == "1"){
                    if(confirm("您对当前的页面所做的修改尚未保存，您确认放弃保存并离开本页面么？")){
                        sessionStorage.setItem("PRODUCT-CATEGORY-EDIT-STATE", "");
                        $this.closest(".zm-popup-blocks").remove();
                        _this.options.callBackCancel();
                    }
                }else{
                    $this.closest(".zm-popup-blocks").remove();
                    return _this.options.callBackCancel();
                }
            });
            /*按钮距离下边20px*/
            this.popupBox.find(".zm-popup-content").css({"position":"relative","width":this.options.width-40});
            if(!this.popupBox.find(".zm-popup-content>div:last").hasClass('iframe-box')){
                this.popupBox.find(".zm-popup-content>div:last").css({"position":"absolute","top":"69px","margin-top":"0","width":"240px"});
                this.popupBox.find(".zm-popup-content>div:last button:first").css({"margin-top":"0","height":"16px","margin-bottom":"0"});
                this.popupBox.find(".zm-popup-content>div:last button:last").css({"margin-top":"0","height":"16px","margin-bottom":"0"});
            }

            // this.popupBox.find(".zm-popup-content>div:last button:first").css({"position":"absolute","top":"0px","left":"40px","margin-top":"0","height":"16px"});
            // this.popupBox.find(".zm-popup-content>div:last button:last").css({"position":"absolute","top":"0px","left":"120px","margin-top":"0","height":"16px"});
            // this.popupBox.find(".contentBtnsStyle").css({"position":"absolute","bottom":"20px","width":"220px","height":"66px"});


            if(this.options.iframeSrc){
                if(this.options.iframeWidth>this.options.width){
                    this.options.iframeWidth=this.options.width;

                }
                if(this.options.iframeHeight>this.options.maxHeight){
                    this.options.iframeWidth=this.options.width-20;
                }

                this.popupBox.find(".iframe-box").css({ width:this.options.iframeWidth-30+'px',height:this.options.iframeHeight+'px',margin:'0 auto',overflow:'hidden'})
                this.popupBox.find(".zm-popup-content").css({padding:0})
            }
            if(this.options.showHeader==1){
                this.popupBox.find(".zm-popup-header").show();
            }else {
                this.popupBox.find(".zm-popup-header").hide();
            }
            if(this.options.contentTextAlign=='left'||this.options.contentTextAlign==1||this.options.contentTextAlign=='1'||this.options.contentTextAlign==''){
                this.popupBox.find(".zm-popup-content").css({textAlign:'left'})
            }
            if(this.options.contentTextAlign=='right'||this.options.contentTextAlign==2||this.options.contentTextAlign=='2'){
                this.popupBox.find(".zm-popup-content").css({textAlign:'right'})
            }
            if(this.options.contentTextAlign=='center'||this.options.contentTextAlign==3||this.options.contentTextAlign=='3'){
                this.popupBox.find(".zm-popup-content").css({textAlign:'center'})
            }
            this.popupBox.find(".zm-popup-content").css({width:this.options.width-40+'px',minHeight:this.options.minHeight+'px',maxHeight:this.options.maxHeight+'px',padding:"10px 30px 20px"});
            this.popupBox.css({marginLeft:-((this.options.width+30)/2)+'px',marginTop:-(this.popupBox.height())/2+'px'});
            if(this.options.callBackKnow){
                $(".btn-popup-know").on("click",function(){
                    $(this).closest(".zm-popup-blocks").remove();
                    return _this.options.callBackKnow();
                })
            }
            if(this.options.callBackKept){
                $(".btn-popup-kept").on("click",function(){
                    $(this).closest(".zm-popup-blocks").remove();
                    return _this.options.callBackKept();
                })
            }
            if(this.options.callBackCancel){
                $(".btn-popup-cancel").on("click",function(){
                    $(this).closest(".zm-popup-blocks").remove();
                    return _this.options.callBackCancel();
                })
            }
        }
    };
    $.fn.zmPopup=function(options){
        var obj=new addPopup(this,options);
        return obj.init();
    };
})(jQuery);

// 参数配置
//
// <script>
// $(document).on("click",".btn-upload",function () {
// $(this).zmPopup({
// skin:'bg-4ab1a7',///'bg-ca6161'警告，'bg-4ab1a7'知道了 。可不设，不设为默认灰色
// width:1500,///弹框宽度
// minHeight:700,//最小高度 可不设
// maxHeight:700,//最小高度 可不设
// showHeader:1,//1为显示，0为隐藏弹框标题头
// tit:"弹窗标题弹窗标题弹窗标题弹窗标题弹窗标题弹窗标题",//弹框标题名，可为空
// content:"谢谢惠顾！",//弹框内容
// contentTextAlign:'left',
// iframeSrc:"<iframe src='https://www.baidu.com' scrolling='no'></iframe>",
// iframeWidth:1200,
// iframeHeight:1200,
// btns:'<button class="btn btn-popup-cancel margin-0-5 ">取消</button><button
// class="btn btn-popup-kept margin-0-5 ">确定</button>',//<button class="btn
// btn-popup-know margin-0-5 ">我知道了</button>
// callBackKnow:function(){console.log("你点击了ok")},
// callBackKept:function(){console.log("你点击了ok")},
// callBackCancel:function(){console.log("你点击了取消")}});
// })
// </script>
